# coding=utf-8
import codecs

crc24_table = [
    0x00000000,
    0x00848401,
    0x00850801,
    0x00018C00,
    0x00861001,
    0x00029400,
    0x00031800,
    0x00879C01,
    0x00802001,
    0x0004A400,
    0x00052800,
    0x0081AC01,
    0x00063000,
    0x0082B401,
    0x00833801,
    0x0007BC00,
    0x008C4001,
    0x0008C400,
    0x00094800,
    0x008DCC01,
    0x000A5000,
    0x008ED401,
    0x008F5801,
    0x000BDC00,
    0x000C6000,
    0x0088E401,
    0x00896801,
    0x000DEC00,
    0x008A7001,
    0x000EF400,
    0x000F7800,
    0x008BFC01,
    0x00948001,
    0x00100400,
    0x00118800,
    0x00950C01,
    0x00129000,
    0x00961401,
    0x00979801,
    0x00131C00,
    0x0014A000,
    0x00902401,
    0x0091A801,
    0x00152C00,
    0x0092B001,
    0x00163400,
    0x0017B800,
    0x00933C01,
    0x0018C000,
    0x009C4401,
    0x009DC801,
    0x00194C00,
    0x009ED001,
    0x001A5400,
    0x001BD800,
    0x009F5C01,
    0x0098E001,
    0x001C6400,
    0x001DE800,
    0x00996C01,
    0x001EF000,
    0x009A7401,
    0x009BF801,
    0x001F7C00,
    0x00A50001,
    0x00218400,
    0x00200800,
    0x00A48C01,
    0x00231000,
    0x00A79401,
    0x00A61801,
    0x00229C00,
    0x00252000,
    0x00A1A401,
    0x00A02801,
    0x0024AC00,
    0x00A33001,
    0x0027B400,
    0x00263800,
    0x00A2BC01,
    0x00294000,
    0x00ADC401,
    0x00AC4801,
    0x0028CC00,
    0x00AF5001,
    0x002BD400,
    0x002A5800,
    0x00AEDC01,
    0x00A96001,
    0x002DE400,
    0x002C6800,
    0x00A8EC01,
    0x002F7000,
    0x00ABF401,
    0x00AA7801,
    0x002EFC00,
    0x00318000,
    0x00B50401,
    0x00B48801,
    0x00300C00,
    0x00B79001,
    0x00331400,
    0x00329800,
    0x00B61C01,
    0x00B1A001,
    0x00352400,
    0x0034A800,
    0x00B02C01,
    0x0037B000,
    0x00B33401,
    0x00B2B801,
    0x00363C00,
    0x00BDC001,
    0x00394400,
    0x0038C800,
    0x00BC4C01,
    0x003BD000,
    0x00BF5401,
    0x00BED801,
    0x003A5C00,
    0x003DE000,
    0x00B96401,
    0x00B8E801,
    0x003C6C00,
    0x00BBF001,
    0x003F7400,
    0x003EF800,
    0x00BA7C01,
    0x00C60001,
    0x00428400,
    0x00430800,
    0x00C78C01,
    0x00401000,
    0x00C49401,
    0x00C51801,
    0x00419C00,
    0x00462000,
    0x00C2A401,
    0x00C32801,
    0x0047AC00,
    0x00C03001,
    0x0044B400,
    0x00453800,
    0x00C1BC01,
    0x004A4000,
    0x00CEC401,
    0x00CF4801,
    0x004BCC00,
    0x00CC5001,
    0x0048D400,
    0x00495800,
    0x00CDDC01,
    0x00CA6001,
    0x004EE400,
    0x004F6800,
    0x00CBEC01,
    0x004C7000,
    0x00C8F401,
    0x00C97801,
    0x004DFC00,
    0x00528000,
    0x00D60401,
    0x00D78801,
    0x00530C00,
    0x00D49001,
    0x00501400,
    0x00519800,
    0x00D51C01,
    0x00D2A001,
    0x00562400,
    0x0057A800,
    0x00D32C01,
    0x0054B000,
    0x00D03401,
    0x00D1B801,
    0x00553C00,
    0x00DEC001,
    0x005A4400,
    0x005BC800,
    0x00DF4C01,
    0x0058D000,
    0x00DC5401,
    0x00DDD801,
    0x00595C00,
    0x005EE000,
    0x00DA6401,
    0x00DBE801,
    0x005F6C00,
    0x00D8F001,
    0x005C7400,
    0x005DF800,
    0x00D97C01,
    0x00630000,
    0x00E78401,
    0x00E60801,
    0x00628C00,
    0x00E51001,
    0x00619400,
    0x00601800,
    0x00E49C01,
    0x00E32001,
    0x0067A400,
    0x00662800,
    0x00E2AC01,
    0x00653000,
    0x00E1B401,
    0x00E03801,
    0x0064BC00,
    0x00EF4001,
    0x006BC400,
    0x006A4800,
    0x00EECC01,
    0x00695000,
    0x00EDD401,
    0x00EC5801,
    0x0068DC00,
    0x006F6000,
    0x00EBE401,
    0x00EA6801,
    0x006EEC00,
    0x00E97001,
    0x006DF400,
    0x006C7800,
    0x00E8FC01,
    0x00F78001,
    0x00730400,
    0x00728800,
    0x00F60C01,
    0x00719000,
    0x00F51401,
    0x00F49801,
    0x00701C00,
    0x0077A000,
    0x00F32401,
    0x00F2A801,
    0x00762C00,
    0x00F1B001,
    0x00753400,
    0x0074B800,
    0x00F03C01,
    0x007BC000,
    0x00FF4401,
    0x00FEC801,
    0x007A4C00,
    0x00FDD001,
    0x00795400,
    0x0078D800,
    0x00FC5C01,
    0x00FBE001,
    0x007F6400,
    0x007EE800,
    0x00FA6C01,
    0x007DF000,
    0x00F97401,
    0x00F8F801,
    0x007C7C00,
]


def crc24(octets):
    crc = 0 & 0x00FFFFFF
    try:
        for octet in octets:
            crc = crc ^ octet
            crc = (crc >> 8) ^ crc24_table[crc & 0x0FF]
    except:
        pass
    return crc & 0x00FFFFFF
